package com.chenwang.measure.base;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.chenwang.measure.R;
import com.chenwang.measure.ui.dialog.LoadingViewDialog;
import com.chenwang.measure.utils.UIUtils;

import static com.chenwang.measure.utils.UIUtils.setStatusBarColor;
import static com.chenwang.measure.utils.UIUtils.setTransparentForWindow;


/**
 * Activity基类,可以在这里注入公共操作器
 */
public abstract class BaseActivity extends AppCompatActivity {

    private LoadingViewDialog mLoadingView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //getWindow().requestFeature(Window.FEATURE_NO_TITLE);//隐藏标题
        //界面中如果有EditText，默认隐藏输入法
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);//隐藏输入法
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//锁定竖屏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);   //应用运行时，保持屏幕高亮，不锁屏
        //setTransparentForWindow(getWindow(),false);
        setStatusBarColor(getResources().getColor(R.color.colorBlue),this );
        setContentView(setLayoutId());
        open();//强制打开蓝牙
        initData();
    }



    /**
     * @return
     * 导入布局
     */
    public abstract int setLayoutId();

    /**
     * 初始化控件,并添加点击滑动等视图事件
     */
    public void initData() {}

    //打开蓝牙
    public void open(){
        if (!BluetoothAdapter.getDefaultAdapter().isEnabled()){
            BluetoothAdapter.getDefaultAdapter().enable();
        }
    }


    public void showLoading(){
        mLoadingView = new LoadingViewDialog();
        mLoadingView.show(getSupportFragmentManager(),"" );
    }
    public void showLoading(String content){
        mLoadingView = new LoadingViewDialog(content);
        mLoadingView.show(getSupportFragmentManager(),"" );


    }

    public void dismissLoading(){
        if (mLoadingView != null){
            mLoadingView.dismiss();
        }

    }



}
